<?php

Loader::import('pspframework.utils.acl.AclInterface');

class AclComponent {


	protected $_Instance = null;

/**
 * Aro 对象
 */
	public $Aro;

/**
 * Aco 对象
 */
	public $Aco;
	
	public function startup(&$controller) {
		$name = Param::read('Acl.classname');		
		if (!class_exists($name)) {
            Loader::import('pspframework.utils.acl.'.$name);
			if (!class_exists($name)) {
				trigger_error(sprintf('Could not find %s.', $name), E_USER_NOTICE);	
			}
		}

		$this->adapter($name);
	}

	public function adapter($adapter = null) {
		if ($adapter) {
			if (is_string($adapter)) {
				$adapter = new $adapter();
			}
			if (!$adapter instanceof AclInterface) {
				trigger_error(sprintf('AclComponent adapters must implement AclInterface'), E_USER_NOTICE);	
			}
			$this->_Instance = $adapter;
			$this->_Instance->initialize($this);
			return;
		}
		return $this->_Instance;
	}
	


	public function check($aro, $aco, $action = "*") {
		return $this->_Instance->check($aro, $aco, $action);
	}

	public function allow($aro, $aco, $action = "*") {
		return $this->_Instance->allow($aro, $aco, $action);
	}


	public function deny($aro, $aco, $action = "*") {
		return $this->_Instance->deny($aro, $aco, $action);
	}


	public function inherit($aro, $aco, $action = "*") {
		return $this->_Instance->inherit($aro, $aco, $action);
	}


	public function grant($aro, $aco, $action = "*") {
		trigger_error(sprintf('AclComponent::grant() is deprecated, use allow() instead'), E_USER_NOTICE);	
		return $this->_Instance->allow($aro, $aco, $action);
	}


	public function revoke($aro, $aco, $action = "*") {
	    trigger_error(sprintf('AclComponent::revoke() is deprecated, use deny() instead'), E_USER_NOTICE);	
		return $this->_Instance->deny($aro, $aco, $action);
	}

}
?>